package com.xintoucloud.gsv.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xintoucloud.gsv.entity.User;
import com.xintoucloud.gsv.mapper.UserMapper;
import com.xintoucloud.gsv.model.DataGrid;
import com.xintoucloud.gsv.model.UserVo;
import com.xintoucloud.gsv.service.UserService;

@Service@Transactional
public class UserServiceImpl implements UserService{
	@Autowired
	private UserMapper userMapper;
	
	
	@Override
	public User login(String uname, String upass) {
		return userMapper.login(uname, upass);
	}


	@Override
	public List<UserVo> userVos() {
		List<UserVo> userVos = userMapper.userVos();
		for(UserVo vo: userVos) {
			vo.getBirthday().toString();
		}
		return userVos;	
	}


	@Override
	public void save(UserVo userVo) {
		userMapper.save(userVo);
	}


	@Override
	public int userDelete(int uid) {
		int rows = userMapper.userDelete(uid);
		return rows;
	}


	@Override
	public boolean userUpdate(UserVo userVo) {
		return userMapper.userUpdate(userVo)>0;
	}


	@Override
	public DataGrid<UserVo> userVosByPageAndSize(int page, int size) {
		DataGrid<UserVo> dataGrid=new DataGrid<>();
		int pageIndex = (page-1)*size;
		List<UserVo> userVos = userMapper.userVosByPageAndSize(pageIndex, size);
		dataGrid.setData(userVos);
		long count = userMapper.count();
		dataGrid.setCount(count);
		if(userVos!=null) {
			//dataGrid.setCode(200);
			dataGrid.setMsg("查询成功");
		}
		return dataGrid;
	}

}
